﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RoadTeam.SysInterface;
using  System.Data;
using RoadTeam.Model;
using RoadTeam.Enums;

namespace RoadTeam.BsSystem.CS
{
   public class CsProject_Sys :RtSysBase, ICsProject
    {
       public DataTable GetProjectIdentifierNotNull(String ActionCode, String OrganID)
       {
           SqlWhere where = new SqlWhere();
           where.StrSqlWhere = @"  App_Identifier IS Not NULL  AND ActionCode='" + ActionCode + "' ";
           where.SelectColumn = @" ProjectID,ProjectCode,ProjectName,SortID,OrganID,App_Identifier ";
           return TbCsProject.Select(where, GlobalConfig.RtConnectionString);
       }
      
       public DataTable GetProjectIdentifierNull(String ActionCode, String OrganID)
       {
           SqlWhere where = new SqlWhere();
           where.StrSqlWhere = @"  App_Identifier IS NULL AND ActionCode='" + ActionCode + "'  ";
           where.SelectColumn = @" ProjectID,ProjectCode,ProjectName,SortID,OrganID,App_Identifier ";
           return TbCsProject.Select(where, GlobalConfig.RtConnectionString);
       }  
       
       public bool UpdateProject(DataTable dt)
       {
         return   TbCsProject.Update(dt, GlobalConfig.RtConnectionString);
       }

       public override string GetIdentitiferByID(string ID)
       {
           SqlWhere where = new SqlWhere();
           where.Info = new TbCsProject() { ProjectID = ID };
           where.SelectColumn = @" App_Identifier ";
           DataTable dt= TbCsProject.Select(where, GlobalConfig.RtConnectionString);
           if (dt.Rows.Count == 0) return String.Empty;
           return dt.Rows[0][0].ToString();
       }

       public string GetIDByIdentitifer(string Identitifer)
       {
           SqlWhere where = new SqlWhere();
           where.Info = new TbCsProject() {  App_Identifier = Identitifer };
           where.SelectColumn = @" Top 1 ProjectID ";
           DataTable dt = TbCsProject.Select(where, GlobalConfig.RtConnectionString);
           if (dt.Rows.Count == 0) return "-1";
           return dt.Rows[0][0].ToString();
       }

       public DataTable GetProjectByProjectIDs(String ProjectIDs)
       {
           SqlWhere where = new SqlWhere();
           where.SelectColumn = @" ProjectID,ProjectName, MaterialFee, LaborCost, Unit,SortID";
           where.StrSqlWhere = @"  ProjectID IN (" + ProjectIDs + ") ";
          return  TbCsProject.Select(where, GlobalConfig.RtConnectionString);
       }




    }
}
